﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfStudy.MyControls;

namespace WpfStudy
{
    /// <summary>
    /// ElectronicsWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ElectronicsWindow : Window
    {
        public ElectronicsWindow()
        {
            InitializeComponent();
            InitElectronicsList();
        }

        private void InitElectronicsList()
        {
            List<Electronics> eleList = new List<Electronics>()
            {
                new Electronics(){Name="Apple Watch Series 6智能手表",Year="2020",Price="3499",Type="Watch"},
                new Electronics(){Name="戴尔(DELL)游匣G15-5511",Year="2021",Price="8999",Type="computer"},
                new Electronics(){Name="HUAWEI-mate40",Year="2020",Price="4599",Type="phone"},
            };

            foreach(Electronics ele in eleList)
            {
                ElectronicsListItemView listView = new ElectronicsListItemView();
                listView.Electronics = ele;
                listBoxElectronics.Items.Add(listView);
            }
        }

        private void listBoxElectronics_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ElectronicsListItemView eleListView = e.AddedItems[0] as ElectronicsListItemView;
            if (null != eleListView)
            {
                detailView.Electronics = eleListView.Electronics;
            }
        }
    }
}
